package door.controller;

import app.nbdevices.modle.revModle.DataChangedModle;
import app.nbdevices.modle.revModle.ServiceModle;
import door.modle.revModle.RevDoorCmdData;
import door.modle.revModle.RevDoorReportData;
import door.service.IDoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class DoorController {

    @Autowired
    @Qualifier("DoorService")
    IDoorService svcDoor;

    public void doorReportData(DataChangedModle dataChanged){
        ServiceModle service = dataChanged.getService();
        RevDoorReportData revDoorReportData=service.getData()
                .toJavaObject(RevDoorReportData.class);
        svcDoor.revReportHandle(dataChanged.getDeviceId(),revDoorReportData);
        //svc.saveEleCycleData(revEleReportData,dataChanged.getDeviceId());
    }

    public void doorCmdData(DataChangedModle dataChanged){
        ServiceModle service = dataChanged.getService();
        RevDoorCmdData revDoorCmdData=service.getData()
                .toJavaObject(RevDoorCmdData.class);
        svcDoor.revCmdHandle(dataChanged.getDeviceId(),revDoorCmdData);
    }

    public void doorUnlock(String InternetDevId){
        //get internet_device_id
        try {
            svcDoor.sendDoorOperCmd(InternetDevId,1,0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void openDoor(String internetDevId)  {
        try {
            svcDoor.sendSwitch(internetDevId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
